package com.kingsoft.dc.khaos.module.spark.util

import java.io.{FileNotFoundException, IOException, InputStream}
import java.util.Properties

import org.apache.commons.io.IOUtils

/**
  * Created by jing on 19/5/4.
  */
object FileConfigReader {

  def load(proFileName: String):Properties = {
    var inputStream: InputStream = null
    val properties = new Properties
    try {
      inputStream = this.getClass.getClassLoader.getResourceAsStream(proFileName)
      properties.load(inputStream)
    }
    catch {
      case e: FileNotFoundException => {
        e.printStackTrace
      }
      case e: IOException => {
        e.printStackTrace
      }
    } finally {
      IOUtils.closeQuietly(inputStream)
    }
    properties
  }

  def loadXml(proFileName: String):Properties = {
    var inputStream: InputStream = null
    val properties = new Properties
    try {
      inputStream = this.getClass.getClassLoader.getResourceAsStream(proFileName)
      properties.loadFromXML(inputStream)
    }
    catch {
      case e: FileNotFoundException => {
        e.printStackTrace
      }
      case e: IOException => {
        e.printStackTrace
      }
    } finally {
      IOUtils.closeQuietly(inputStream)
    }
    properties
  }


}
